/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2022-2022.
 * Description: support dim kernel
 * Author: chenjingwen6 <chenjingwen6@huawei.com>
 * Create: 2022-08-05
 */
#include <linux/export.h>
#ifdef CONFIG_LIVEPATCH
#include <linux/notifier.h>
#endif
#include <linux/rtos/dim_kernel.h>
#include <asm/sections.h>

unsigned long dim_kernel_text_start(void)
{
	return (unsigned long)_stext;
}
EXPORT_SYMBOL_NS(dim_kernel_text_start, HW_RTOS_NS);

unsigned long dim_kernel_text_end(void)
{
	return (unsigned long)_etext;
}
EXPORT_SYMBOL_NS(dim_kernel_text_end, HW_RTOS_NS);

#ifdef CONFIG_JUMP_LABEL
extern struct jump_entry *dim_jump_label_start(void)
{
	return __start___jump_table;
}
EXPORT_SYMBOL_NS(dim_jump_label_start, HW_RTOS_NS);

extern struct jump_entry *dim_jump_label_end(void)
{
	return __stop___jump_table;
}
EXPORT_SYMBOL_NS(dim_jump_label_end, HW_RTOS_NS);

void dim_jump_label_lock(void)
{
	jump_label_lock();
}
EXPORT_SYMBOL_NS(dim_jump_label_lock, HW_RTOS_NS);

void dim_jump_label_unlock(void)
{
	jump_label_unlock();
}
EXPORT_SYMBOL_NS(dim_jump_label_unlock, HW_RTOS_NS);
#endif /* CONFIG_JUMP_LABEL */

#ifdef CONFIG_LIVEPATCH
static BLOCKING_NOTIFIER_HEAD(klp_notifier);

int register_klp_notifier(struct notifier_block *nb)
{
	return blocking_notifier_chain_register(&klp_notifier, nb);
}
EXPORT_SYMBOL_NS(register_klp_notifier, HW_RTOS_NS);

int unregister_klp_notifier(struct notifier_block *nb)
{
	return blocking_notifier_chain_unregister(&klp_notifier, nb);
}
EXPORT_SYMBOL_NS(unregister_klp_notifier, HW_RTOS_NS);

void klp_notifier_call_chain(enum klp_notifier_state state, struct klp_patch *patch)
{
	blocking_notifier_call_chain(&klp_notifier, (unsigned long)state, patch);
}
#endif /* CONFIG_LIVEPATCH */
